package com.xxx.controller;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.xxx.common.dto.FileInfo;
import com.xxx.common.utils.FileUtil;
import com.xxx.interceptor.AuthorityType;
import com.xxx.interceptor.UserAuthority;
/**
 * @ClassName: UmeditorController 
 * @Description: 百度编辑器文件上传
 */
@RestController
@RequestMapping("/umeditor/*")
@UserAuthority(authorityType = AuthorityType.NoValidate)
public class UmeditorController {
	
	@Value("${server.context-path:}")
	private String contextPath; 
	
	/**
	 * @Title: upload 
	 * @Description: Ueditor 上传
	 * @param request
	 * @param upfile
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("upload")
	public String upload(HttpServletRequest request,MultipartFile upfile) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		if(upfile != null){
			FileInfo fileUpload = FileUtil.compressUpload(upfile, 1080,760);
			map.put("url", contextPath + File.separator + fileUpload.getLocalPath());
			map.put("state", "SUCCESS");
		}
		return JSON.toJSONString(map);
	}

}
